/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.com.pps.services;

import java.util.ArrayList;
import vn.com.pps.dao.ITeacherDAO;
import vn.com.pps.entities.Teacher;
import vn.com.pps.web.ui.TeacherTableItem;

/**
 *
 * @author Dai
 */
public class TeacherService implements ITeacherService {

    private ITeacherDAO teacherDAO;

    public void setTeacherDAO(ITeacherDAO teacherDAO) {
        this.teacherDAO = teacherDAO;
    }

    @Override
    public int countTeacher(String whereClause) {
        return teacherDAO.getCount(whereClause);
    }

    @Override
    public ArrayList<TeacherTableItem> getTeachers(int pageNo, int pageSize, String whereClause) {
        ArrayList<TeacherTableItem> teacherTableItems = new ArrayList<TeacherTableItem>();
        for (Teacher teacher : teacherDAO.getTeachers(pageNo, pageSize, whereClause).getPageItems()) {
            teacherTableItems.add(new TeacherTableItem(teacher));
        }
        return teacherTableItems;
    }

    @Override
    public ArrayList<TeacherTableItem> getTeachers() {
        ArrayList<TeacherTableItem> teacherTableItems = new ArrayList<TeacherTableItem>();
        for (Teacher teacher : teacherDAO.getTeachers()) {
            teacherTableItems.add(new TeacherTableItem(teacher));
        }
        return teacherTableItems;
    }

    @Override
    public Teacher getTeacher(Integer id) {
        return teacherDAO.getTeacher(id);
    }

    @Override
    public int saveTeacher(Teacher teacher) {
        return teacherDAO.insert(teacher);
    }

    @Override
    public int editTeacher(Teacher teacher) {
        return teacherDAO.update(teacher);
    }

}
